package com.zlkj.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zlkj.manager.domain.SysCity;
import com.zlkj.manager.service.ISysCityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 城市数据Controller
 * 
 * @author ruoyi
 * @date 2022-03-04
 */
@RestController
@RequestMapping("/manager/city")
public class SysCityController extends BaseController
{
    @Autowired
    private ISysCityService sysCityService;

    /**
     * 查询城市数据列表
     */
    @PreAuthorize("@ss.hasPermi('manager:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCity sysCity)
    {
        startPage();
        List<SysCity> list = sysCityService.selectSysCityList(sysCity);
        return getDataTable(list);
    }

    /**
     * 获取城市下拉树列表
     */
    @GetMapping("/tree")
    public AjaxResult cityTree(SysCity city)
    {
        List<SysCity> citys = sysCityService.selectCityList(city);
        return AjaxResult.success(sysCityService.buildCityTreeSelect(citys));
    }

    /**
     * 导出城市数据列表
     */
    @PreAuthorize("@ss.hasPermi('manager:city:export')")
    @Log(title = "城市数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCity sysCity)
    {
        List<SysCity> list = sysCityService.selectSysCityList(sysCity);
        ExcelUtil<SysCity> util = new ExcelUtil<SysCity>(SysCity.class);
        util.exportExcel(response, list, "城市数据数据");
    }

    /**
     * 获取城市数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:city:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysCityService.selectSysCityById(id));
    }

    /**
     * 新增城市数据
     */
    @PreAuthorize("@ss.hasPermi('manager:city:add')")
    @Log(title = "城市数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCity sysCity)
    {
        return toAjax(sysCityService.insertSysCity(sysCity));
    }

    /**
     * 修改城市数据
     */
    @PreAuthorize("@ss.hasPermi('manager:city:edit')")
    @Log(title = "城市数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCity sysCity)
    {
        return toAjax(sysCityService.updateSysCity(sysCity));
    }

    /**
     * 删除城市数据
     */
    @PreAuthorize("@ss.hasPermi('manager:city:remove')")
    @Log(title = "城市数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCityService.deleteSysCityByIds(ids));
    }
}
